from typing import Optional
from pydantic import BaseModel, Field


class UserBase(BaseModel):
    username: str
    nick_name: str
    email: str
    mobile: str
    city: str
    profile_picture: str


class UserCreate(BaseModel):
    password: str


class User(UserBase):
    id: int
    is_active: bool

    class Config:
        orm_mode = True


class LoginUser(User):
    token: str


class UserInfo(BaseModel):
    nick_name: Optional[str] = Field(None, max_length=20, regex=r'[\u4e00-\u9fa5]+', title="中文昵称")
    mobile: Optional[str] = Field(None, regex=r'^1[3-9]\d{9}$', title="手机号")
    email: Optional[str] = Field(None, regex=r'^\w+?@.+\.(com|cn|org|net|com\.cn)$', title="邮箱")
    profile_picture: Optional[str] = Field(None, title="用户头像")


class RegistUser(UserInfo):
    username: Optional[str] = Field(..., max_length=20, regex=r'^[a-zA-z]\w+$')
    password: Optional[str] = Field(..., min_length=6)


class CreateUserInfo(BaseModel):
    id: str
    username: str
    nick_name: Optional[str]
    is_active: bool

    # token: str

    class Config:
        orm_mode = True
